var url = "http://palerock.cn/h5_back";
//        var net = "http://localhost:8080";
var app = angular.module('app', []);

app.controller('login', function ($scope, $http) {
    $scope.userPhoneNumber = '';
    $scope.userLoginPsw = '';



    $scope.getlogin = function(){
        var loginInfo = {'userPhoneNumber':$scope.userPhoneNumber,'userLoginPsw':$scope.userLoginPsw};
        $http.post(url +'/login',loginInfo).then(function(res){

            if(!res.data.error){

                location.href = "index.html";
                localStorage.setItem("token", res.data.token);
                console.log(document.cookie);
                alert(1);
            }else{
                $('#popup>p').html(""+res.data.mes);
                $('#popup').css('display','block');
            }
        },function(){
            $('#popup>p').html("登录失败，网络错误");
            $('#popup').css('display','block');
        });

    };

    $scope.registering = function(){
        var registorInfo = {'userPhoneNumber':$scope.userPhoneNumber,'userLoginPsw':$scope.userLoginPsw};
        $http.post(url+'/register',registorInfo).then(function(res){

            if(!res.data.error){
                var loginInfo = {'userPhoneNumber':$scope.userPhoneNumber,'userLoginPsw':$scope.userLoginPsw};
                $http.post(url +'/login',loginInfo).then(function(res){

                    if(!res.data.error){

                        $('#popup>p').html("正在快速登录");
                        $('#popup').css('display','block');
                        localStorage.setItem("token", res.data.token);
                        $('.close').click(function(){
                            location.href = "index.html";
                        });

                    }else{

                        $('#popup>p').html(""+res.data.mes);
                        $('#popup').css('display','block');

                    }
                },function(){
                    $('#popup>p').html("登录失败，网络错误");
                    $('#popup').css('display','block');

                });

            }else{
                $('#popup>p').html(""+res.data.mes);
                $('#popup').css('display','block');

                s=true;

            }
        },function(){
            $('#popup').css('display','block');
            $('#popup>p').html("注册失败，请重新注册");


        })
    };

});